package com.wdemo.controller;

import com.wdemo.service.EmbeddingService;
import com.wdemo.service.impl.EmbeddingServiceImpl;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName EmbeddingController
 * @Description TODO
 * @Author WDEMO
 * @Date 2025/8/29 17:25
 */

@RestController
@RequestMapping("/embedding")
@CrossOrigin
@RequiredArgsConstructor
public class EmbeddingController {

    private final VectorStore vectorStore;
   private EmbeddingService embeddingService;


    @PostConstruct
    public void init(){
        EmbeddingService embeddingService = new EmbeddingServiceImpl(vectorStore);
        this.embeddingService=embeddingService;
    }
    /**
     * 保存向量数据
     * @param messages
     */
    @PostMapping
    public void saveVectorStore(@RequestParam("messages") List<String> messages){
        embeddingService.saveVectorStore(messages);
    }


    /**
     * 搜索全部数据
     * @return
     */
    @GetMapping("/search/all")
    public List<Document> searchAll(){
      return embeddingService.searchAll();
    }


    /**
     * 内容搜索
     * @return
     */
    @GetMapping("/search")
    public List<Document> search(@RequestParam("message") String message){
       return embeddingService.search(message);
    }
}
